/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package global.sandbox.xmlutilities.demo;

import global.sandbox.xmlutilities.XMLTools;
import javax.xml.transform.Source;
import org.w3c.dom.Document;

public class SchemaValidator {
    
    public static void validateXML(Source doc, Source schema)
            throws SchemaValidatorException, ValidationException {
        String result;
        
        try {
            result = XMLTools.validateXmlUsingSchema(doc, schema);
        } catch (Exception ex) {
            throw new SchemaValidatorException(ex);
        }
        
        if (result != null) {
            throw new ValidationException(result);
        }
    }
    
    public static void validateXML(Document doc, Document schema)
            throws SchemaValidatorException, ValidationException {
        validateXML(
                XMLTools.documentToDOMSource(doc),
                XMLTools.documentToDOMSource(schema));
    }
    
    public static class SchemaValidatorException extends Exception {
        
        private static final long serialVersionUID = 1L;
        
        public SchemaValidatorException(Throwable cause) {
            super(cause);
        }
        
    }
    
    public static class ValidationException extends Exception {
        
        private static final long serialVersionUID = 1L;
        
        public ValidationException(String message) {
            super(message);
        }
        
    }
    
}
